home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
comm
/
ca29_3.zip
/
LEARN.SRC
< prev
next >
Wrap
Text File
|
1992-09-21
|
50KB
|
1,811 lines
SET TTHRU OFF ; Make first to allow typeahead
S19 = "Learn ver 1.0 " ; 20 chars long
; ----- Learn: Learn mode shell for COM-AND
;
; R.McG; 8/89, Chicago
; ----------------------------------------------------------------
; Usages:
; S19 -----> Legend line
; S18 -----> Load-time drive:subdirectory (for exit)
; S17 -----> Load-time download d:subdir (for exit)
; S16 -----> Output file name
; S12 -----> Text before last line displayed to screen
; S11 -----> Last line displayed to screen
; S10 -----> Current output buffer
;
; N99 -----> Number of lines on screen
; N96 -----> Current receive area cursor
; N95 -----> Current receive area cursor
; N94 -----> Current Kbd area cursor
; N93 -----> Current Kbd area cursor
; N92 -----> Saved cursor on entry
; N91 -----> Saved cursor on entry
; N90 -----> Current output buffer index
;
; FLAG(0) -> ESCAPE has been hit if ON
; FLAG(1) -> Off: no printer on: Printer in use
; FLAG(2) -> Off: log not used on: Log was used
; FLAG(8) -> Off: learning, on: learning suspended
; FLAG(9) -> Off: in line mode, on: in character mode
; -----------------------------------------------------------------------
;
; Initialization
;
CURSOR N91,N92 ; Read current cursor
LEGEND S19 ; Set initial legend
SUBDIR S18 ; Read current subdir
DLDIR S17 ; Read current download subdir
SSIZE N99 ; Get current screen size
SAVE 0,0,N99-2,79 ; Save original screen
ON ESCAPE GOSUB ESCAPE ; Escape action
SET FLAG(1) OFF ; Set printer on/off flag
IF STRCMP "_PRIN" "ON" ; .. as we only turn printer on
SET FLAG(1) ON ; .. during receive portion
PRINTER OFF ; Turn printer off unconditionally
ENDIF
;
; Ask for an output file name
;
Get_Output:
S1 = "Enter a file name to be output:"
GOSUB Ask_File ; Ask for an output file
IF NOT SUCCESS EXIT ; If ESC'd then stop
S16 = S0 ; Save fname
;
; Test for file existing
;
IF ISFILE S16 ; If file exists
S0 = S16 *" already exists. Overwrite it? Y/N (cr=no)"
GOSUB Ask_YN
IF NOT SUCCESS GOTO Get_Output
ENDIF
;
; Open the output file, no append
;
FOPENO S16 TEXT ; Open output file
IF NOT SUCCESS
S0 = "Error opening output file: "*S16
GOSUB Error ; Report
GOTO Get_output
ENDIF
;
; Perform other initialization
;
GOSUB Initial ; Save initial settings
SET CHAT OFF ; Turn off chat
GOTO START ; And continue
;
; ----- Subroutine: Escape - Set a flag for mainline loop
;
Escape:
SET FLAG(0) ON ; Flag fact
RETURN ; And continue
;
;------ Subroutine: Terminate the all LEARN script activity
;
End_Learn:
DWINDOW CLEAR ; Clear display window
IF FLAG(2) and STRCMP "_LOGG" "ON "
WRITE "LOG CLOSE!" ; FInish logging if on and turned on within
LOG CLOSE
ENDIF
WRITE "^Z" 2 ; Terminate w/EOF
FCLOSEO ; Close output file
SET DLDIR S17 ; Reset DLDIR to load time
CHDIR S18 ; Reset default subdir to load time
RESTORE ; Restore screen
LOCATE N91,N92 ; Restore cursor
IF FLAG(1) ; Set printer according to current state
PRINTER ON
ELSE
PRINTER OFF
ENDIF
RETURN ; Rtn to caller
;
;------ Subroutine: Ask if Exit to be taken
;
Exit:
S0 = "Do you wish to terminate LEARN? Enter Y to terminate."
GOSUB Ask_YN
IF SUCCESS ; IF answer is 'y'
GOSUB End_Learn ; Terminate
EXIT ; And stop script
ENDIF
SET FLAG(0) OFF ; Clear ESC flag
RETURN ; And continue
;
; ----- Main-line: Draw the screen, and begin loop
;
Start:
N90 = 0 ; Initialize buffer index
S11 = "" ; Init last line received
S12 = "" ; Init next ot last line received
SET FLAG(0) OFF ; Init ESC hit flag
SET FLAG(9) OFF ; Init to line mode
SET FLAG(8) OFF ; Init to not held
GOSUB Screen ; Draw screen
LOCATE 1,1 ; Set cursor
DWINDOW N99-12,2 N99-12 77 ; Set kbd scrolling region
GOTO Main
;
; Write a line (in S0, less CRLF) to the output file
;
Output:
WRITE S0 ; Write to file
WRITE "!" ; Add a crlf
;
; Display received text, and wait for a keypress
;
Main:
LOCATE N93,N94 ; Set kbd cursor
IF FLAG(0) GOSUB Exit ; If ESC pressed, ask if to exit
IF NOT HITKEY ; If nothig on kbd
IF RECEIVE GOSUB Receive ; Allow incoming text to be displayed
GOTO Main
ENDIF
;
; We have a keypress pending
;
KEYGET S1 ; Read a single key
LENG S1 N0 ; Compute length of KEYGET
SWITCH N0
CASE 1 ; length = 1
GOTO ASCII
ENDCASE
CASE 2 ; length = 2
GOTO CONTROL
ENDCASE
CASE 4 ; length = 4
GOTO FUNCTION
ENDCASE
ENDSWITCH
GOTO Main ; And continue
;
; Update the keyboard display
;
KbdDisp:
IF GT N90 0
S0 = S10(0:n90-1) ; COpy current buffer
PRESERVE S0 ; Make displayable
ATSAY N99-12,2 (Default) S0 *" "
ENDIF
N94=N90+2 ; Set new col #
GOTO Main
;
; ----- Subroutine: Handle receipt of text
;
Receive:
DWINDOW 1, 0,(N99-14),79 ; Set rcv scrolling region
IF FLAG(1) PRINTER ON ; Turn on printer while reading comm
LOCATE N95,N96 ; Set rcv cursor
S12 = S11 ; Save previous line read
RGET S11 80 1 ; Read new text, max wait 1 sec
CURSOR N95,N96 ; Read new rcv area cursor
IF FLAG(1) PRINTER OFF ; Turn off printer now
DWINDOW N99-12,2 N99-12,77 ; Set kbd scrolling region
RETURN
;
; ASCII char entered: length in N0 is 1
;
ASCII:
IF FLAG(8) ; If learn held
PRESERVE S1 ; ..
TRANSMIT S1 ; Send the char
GOTO Main ; .. and no more
ENDIF
;
; Catch buffer overflow (limit kbd buffer to 60 chars)
;
IF GT (N90+2) 60
SOUND 100,100
GOTO Main
ENDIF
;
; Buffer the char (preserving for TRANSMIT)
;
S10(N90:N90) = S1 ; Buffer keystroke
INC N90
IF STRCMP S1 "!" or STRCMP S1 "^"
S10(N90:N90) = S1 ; DOuble special chars to PRESERVE for TRANSMIT
INC N90
ENDIF
;
; If CHAR mode, send immediate
;
IF FLAG(9) GOTO Transmit ; If char mode transmit immediately
GOTO KbdDisp ; Update kbd display
;
; Handle control chars: length in N0 is 2
;
Control:
S0 = "0x"*S1 ; Make hex form of #
N0 = S0 ; If ctl char (e.g. 0d for c/r)
N0 = N0+64 ; Convert to ASCII @,A,B,...
S0 = "^" ; Store delimiter
ITOC N0 S0(1:1) ; Store char being ctl'd
;
; Simply xmit if LEARN HELD
;
IF FLAG(8) ; If learn held
TRANSMIT S0 ; Send the char
GOTO Main ; .. and no more
ENDIF
;
; Catch special control chars
;
IF (NOT FLAG(9)) and STRCMP S1 "08" ; Catch backspace here
GOTO Backspace ; .. in line mode
ENDIF
IF STRCMP S1 "0D" ; Catch c/rs
GOTO RETURN ; .. in either line or char mode
ENDIF
IF GT (N90+2) 60 ; Handle buffer overflow here
SOUND 100,100
GOTO Main
ENDIF
;
; Buffer the remainder as "^" chars
;
S10(N90:N90+1) = S0(0:1) ; Store delimiter
N90 = N90+2
IF FLAG(9) GOTO Transmit ; If char mode transmit directly
GOTO KbdDisp ; Update kbd display
;
; Backspace entered
;
Backspace:
IF ZERO N90
GOTO KbdDisp
ENDIF
DEC N90
IF STRCMP S10(N90-1:N90-1) "^" or STRCMP S10(N90-1:N90) "!!"
DEC N90
ENDIF
GOTO KbdDisp ; Update kbd display
;
; Carriage return entered
;
Return:
IF NOT ZERO N90
S10 = S10(0:N90-1)*"!"
ELSE
S10 = "!"
ENDIF
N90 = N90+1
;
; Execute the current buffer
;
Transmit:
GOSUB Waitfor ; Emit a WAITFOR
;
; Now, emit a TRANSMIT statement
;
WRITE "TRANSMIT `"" ; Write TRANSMIT statement
IF STRCMP S10(N90-1:N90-1) "!!"
WRITE S10 N90-1 ; Write string to be xmitted less final c/r